﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using pandx.Mulan.Configuration;
using pandx.Mulan.Web;

namespace pandx.Mulan.EntityFrameworkCore
{
    /* This class is needed to run "dotnet ef ..." commands from command line on development. Not used anywhere else */
    public class MulanDbContextFactory : IDesignTimeDbContextFactory<MulanDbContext>
    {
        public MulanDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<MulanDbContext>();
            var configuration = AppConfigurations.Get(WebContentDirectoryFinder.CalculateContentRootFolder());

            MulanDbContextConfigurer.Configure(builder, configuration.GetConnectionString(CoreConsts.ConnectionStringName));

            return new MulanDbContext(builder.Options);
        }
    }
}

